package playitas

import playas.*

import java.text.DecimalFormat

class GeoTagLib {

    static namespace = 'geo'

    def geograficoService


    def distancia = { attrs ->
        def d = Distancia.distanciaGeodesica(attrs.lat1 as Double, attrs.long1 as Double, attrs.lat2 as Double, attrs.long2 as Double)

        if (d < 1) {
            d = (d * 1000) as int
            out << "${d} metros"
        } else if (d < 10) {
            out << "${new DecimalFormat("0.0").format(d).replaceAll(",",".")} kms"
        } else {
            out << "${new DecimalFormat("0").format(d)} kms"

        }
    }
}

